﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TheatreManagementSystem
{
    public static class TicketFactory
    {
        static int uniqueNumberCounter = 0;

        public static Ticket CreateNewTicket(Customer customer, Performance performance, Seat seat,Seller seller)
        {
            if (performance.isSeatTaken(seat)=='X')
            {
                throw new SeatTakenException(seat);
            }

            performance.MakeSeatTaken(seat);
            seller.SoldTicketsMonthly++;
            uniqueNumberCounter++;
            decimal price = performance.PriceOfPerformance;
            
            if (customer == null)
            {
                return new Ticket(uniqueNumberCounter.ToString().PadLeft(8, '0'), performance.NameOfPlay, performance.DateOfPerformance, seat, performance.HallName, price);
            }
            else
            {
                price -= price * customer.GetDiscount();
                customer.AttendNewPerformance();
                return new Ticket(uniqueNumberCounter.ToString().PadLeft(8, '0'), performance.NameOfPlay, performance.DateOfPerformance, seat, performance.HallName, price, customer.FirstName + " " + customer.LastName);
            }
        }

        public static Ticket CreateNewTicket(Performance performance, Seat seat, Seller seller)
        {
            return CreateNewTicket(null, performance, seat, seller);
        }
    }
}
